package com.ccrc.base.dao.impl;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Criteria;

import com.ccrc.base.dao.Dao;



public class DaoImpl<T> extends GenericDaoImpl implements Dao<T> {
	
	/**
     * 实体类型
     */
    protected Class<T> entityClass;
    
    public DaoImpl(){
    	
    }
	
	public DaoImpl(Class<T> entityClass) {
		super();
		this.entityClass = entityClass;
	}
	

	/**
	 * 根据ID获取数据对象
	 */
	@Override
	public T get(Serializable id) {
		return get(entityClass, id);
	}
	
	/**
	 * 根据ID删除数据对象
	 */
	@Override
	public void deleteById(Serializable id) {
		deleteById(entityClass, id);
	}
	
	protected Criteria createCriteria(){
	    return createCriteria(entityClass);
	}
	    
	
	/**
	 * 查询全部数据
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<T> list() {
		return createCriteria().list();
	}

	protected TopQuery<T> topQuery(int maxResults){
        return topQuery(maxResults, entityClass, null);
    }
    
    protected TopQuery<T> topQuery(int maxResults, String cacheRegion){
        return topQuery(maxResults, entityClass, cacheRegion);
    }
}
